#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>


int main(int argc, char**  argv)
{
    // linux 系统专用函数实现拷贝文件--------------------
    int fd1, fd2;
    int ret;
    char buf[1024];

    fd1 = open(argv[1], O_RDONLY);
    fd2 = open(argv[2], O_WRONLY | O_CREAT, 0666);

    while((ret = read(fd1, buf, sizeof(buf))) > 0)
    {
        write(fd2, buf, ret);
    }

    close(fd1);
    close(fd2);
    
    // 标准库 c 函数实现拷贝文件-----------------------
    /*
    FILE* fd1, *fd2;
    int ret;
    char buf[1024];

    fd1 = fopen(argv[1], "rb");
    fd2 = fopen(argv[2], "wb");

    while((ret = fread(buf, 1, sizeof(buf), fd1)) > 0)
    {
        fwrite(buf, 1, ret, fd2);
    }

    fclose(fd1);
    fclose(fd2);  
    */

   // 将文件内容打印到当前终端------------------------
   /*
    while(1)
    {
        fwrite("a", 1, 1, stdout);
        fflush(stdout);
        sleep(1);
    }
    */
    return 0;
}